// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org.

package nl.justobjects.pushlet.util;

import java.io.File;

import nl.justobjects.pushlet.core.ConfigDefs;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * Logging wrapper.
 * <p/>
 * Provides a hook to direct logging to your own logging library.  Override the DefaultLogger class by setting
 * "logging.class" in pushlet.properties to your own logger
 * to integrate your own logging library.
 *
 * @author Just van den Broecke
 * @version $Id: Log.java,v 1.4 2007/11/23 21:29:43 justb Exp $
 */
public class Log implements ConfigDefs {
	//private static DefaultLogger logger = new DefaultLogger();
	
	private static String LOG4J_CONFIG_FILENAME = "log4j.properties";
	
	private static Logger logger;

	/**
	 * General purpose initialization.
	 */
	static public void init(String webInfPath) {
		String configFilename = webInfPath + File.separator + "classes" + File.separator + LOG4J_CONFIG_FILENAME;
		logger = Logger.getLogger(Log.class.getName());
		
		PropertyConfigurator.configure(configFilename);

		logger.info("Logging intialized logger class=" + logger.getClass());
		logger.info("LOG4J_CONFIG_FILENAME=" + configFilename);
	}

	/**
	 * Log message for trace level.
	 *
	 * @param aMessage the message to be logged
	 */
	static public void trace(String aMessage) {
		logger.debug(aMessage);
	}

	/**
	 * Log message for debug level.
	 *
	 * @param aMessage the message to be logged
	 */
	static public void debug(String aMessage) {
		logger.debug(aMessage);
	}

	/**
	 * Log message for info level.
	 *
	 * @param aMessage the message to be logged
	 */
	static public void info(String aMessage) {
		logger.info(aMessage);
	}

	/**
	 * Log message for warning level.
	 *
	 * @param aMessage the message to be logged
	 */
	static public void warn(String aMessage) {
		logger.warn(aMessage);
	}

	/**
	 * Log message for warning level with exception.
	 *
	 * @param aMessage   the message to be logged
	 * @param aThrowable the exception
	 */
	static public void warn(String aMessage, Throwable aThrowable) {
		logger.warn(aMessage, aThrowable);
	}

	/**
	 * Log message for error level.
	 *
	 * @param aMessage the message to be logged
	 */
	static public void error(String aMessage) {
		logger.error(aMessage);
	}

	/**
	 * Log message (error level with exception).
	 *
	 * @param aMessage   the message to be logged
	 * @param aThrowable the exception
	 */
	static public void error(String aMessage, Throwable aThrowable) {
		logger.error(aMessage, aThrowable);
	}

	/**
	 * Log message for fatal level.
	 *
	 * @param aMessage the message to be logged
	 */
	static public void fatal(String aMessage) {
		logger.fatal(aMessage);
	}

	/**
	 * Log message (fatal level with exception).
	 *
	 * @param aMessage   the message to be logged
	 * @param aThrowable the exception
	 */
	static public void fatal(String aMessage, Throwable aThrowable) {
		logger.fatal(aMessage, aThrowable);
	}

}

/*
* $Log: Log.java,v $
* Revision 1.4  2007/11/23 21:29:43  justb
* add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
*
* Revision 1.3  2007/11/23 21:10:17  justb
* add hooks for custom logging (you can override DefaultLogger in pushlet.properties)
*
* Revision 1.2  2005/02/21 11:15:59  justb
* support log levels
*
* Revision 1.1  2005/02/18 10:07:23  justb
* many renamings of classes (make names compact)
*
* Revision 1.7  2004/09/03 22:35:37  justb
* Almost complete rewrite, just checking in now
*
* Revision 1.6  2004/08/12 13:16:08  justb
* make debug flag false
*
* Revision 1.5  2004/03/10 14:01:55  justb
* formatting and *Subscriber refactoring
*
* Revision 1.4  2003/08/15 09:54:46  justb
* fix javadoc warnings
*
* Revision 1.3  2003/08/15 08:37:40  justb
* fix/add Copyright+LGPL file headers and footers
*
* Revision 1.2  2003/08/12 09:42:47  justb
* enhancements
*
* Revision 1.1  2003/08/12 08:46:00  justb
* cvs comment tags added
*
*
*/